<template>
	<view class="repassword">
		<input class="user__set__input" type="text"  password placeholder="输入旧密码" v-model="oldpassword"/>
		<input class="user__set__input" type="text" password placeholder="输入新密码" v-model="newpassword"/>
		<input class="user__set__input" type="text" password placeholder="确认新密码" v-model="renewpassword"/>
		<button type="default" class="user__set__btn" :loading="isloading" :class="[{'user__set__btn--disable':isEnabled}]" @tap="submit">完成</button>
	</view>
</template>

<script setup> 
	import {check} from '../../common/verification.js'
	import {ref,computed} from 'vue';
	// 旧密码
	const oldpassword = ref("")
	// 新密码
	const newpassword = ref("")
	// 确认密码
	const renewpassword = ref("")
	
	const isloading = ref(false)
	
	const isEnabled = computed(()=>{
		return oldpassword.value!=''&&newpassword.value!=''&&renewpassword.value!='';
	})
	
	
	// 提交数据
	function submit(e){
		if(isloading.value||!isEnabled.value)return;
		if(!(check(oldpassword.value,/^\w{4,9}$/,"密码长度在{4,9}")&&
		check(newpassword.value,/^\w{4,9}$/,"密码长度在{4,9}")&&
		check(renewpassword.value,/^\w{4,9}$/,"密码长度在{4,9}"))){
			return false;
		}
		if(newpassword.value!=renewpassword.value){
			uni.showToast({
				title:"新密码和确认密码不一致!",
				icon:"exception",
			})
			return false;
		}		
		isloading.value=true;
		
		setTimeout(()=>{
			isloading.value=false;
		},1000)
	}
	
</script>

<style lang="scss" scoped>
	@import '../../common/from.scss';
 .repassword{
	 padding: 20upx;
	 width: 100%;
	 box-sizing: border-box;
	
	 
 }

</style>
